<?php defined('SYSPATH') or die('No direct access allowed.');

class Message
{
    const ERROR = 1;
    const WARNING = 2;
    const NOTICE = 3;

    //array message

    public static function set($message,$type)
    {
        $current_message = Session::instance()->get('message');

        if(!empty($current_message))
            $current_message = unserialize($current_message);
        else
            $current_message = array();

        if(isset($current_message[$type]))
            $current_message[$type][] = $message;
        else
            $current_message[$type] = array($message);

        Session::instance()->set('message',  serialize($current_message));
    }

    public static function get($template = 'message')
    {
        $current_message = Session::instance()->get('message');

        if($current_message)
        {
            self::_clear();
            return unserialize($current_message);
        }
    }

    private static function _clear()
    {
        Session::instance()->delete('message');
    }
}

